package com.scy.hospitalmanager.until;

import com.github.pagehelper.PageInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回结果集的工具类
 */
public class ResponseMap {

    private Integer errno;
    private String msg;
    private Map<String, Object> data = new HashMap<>();


    private static final ResponseMap OK = new ResponseMap(0);
    private static final ResponseMap NO = new ResponseMap(1);

    ResponseMap(Integer errno) {
        this(errno, "");
    }

    ResponseMap(Integer errno, String msg) {
        this.errno = errno;
        this.msg = msg;
    }

    public static ResponseMap OK() {
        return OK("success");
    }

    public static ResponseMap OK(String msg) {
        return OK(msg, null);
    }

    public static ResponseMap OK(PageInfo<Object> pageInfo) {
        return OK("success", pageInfo);
    }

    public static ResponseMap OK(Object data) {
        return OK("success", data);
    }

    public static ResponseMap OK(String msg, Object data) {
        return OK.setData(data).setMsg(msg);
    }

    public static ResponseMap NO() {
        return NO("failure");
    }

    public static ResponseMap NO(String msg) {
        return NO(msg, new HashMap<>());
    }

    public static ResponseMap NO(Map<String, Object> data) {
        return NO("failure", data);
    }

    public static ResponseMap NO(String msg, Object data) {
        return NO.setData(data).setMsg(msg);
    }

    public Integer getErrno() {
        return errno;
    }

    public ResponseMap setErrno(Integer errno) {
        this.errno = errno;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public ResponseMap setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public ResponseMap setData(Object data) {
        this.data.put("data", data);
        return this;
    }

}
